#ifndef CNC_BASE_MILL_MEMORY_H
#define CNC_BASE_MILL_MEMORY_H

#include "millmem_.h"
// provided interfaces
//	#include "millgdata.h"
// basic component model
#include <bcm/bcm.h>

namespace cnc {

	namespace base {

		/**
		@brief Milling Machine Parameter Database Component.
		
		This class implements a milling machine parameter database component.
		*/

		class MillMemory : public bcm::Identifier<bcm::Component>,
			public MillMemoryImpl
		{
		protected:
			MillMemory() : bcm::Identifier<bcm::Component>("millmem", "Mill Memory")
			{
			}
		protected: // bcm::Component
			virtual bcm::IdentifierData *getProvidedInterfaceTable()
			{
				static bcm::IdentifierData idData[] = {
					{ "taskctl", "Task Control" },
					{ "gdata", "Global Data" },
					{ "millgdata", "Mill Global Data" },
					{ 0, 0 }
				};
				return idData;
			}
			virtual bcm::IdentifierData *getRequiredInterfaceTable()
			{
				static bcm::IdentifierData idData[] = {
					{ "millpdata", "Mill Persistent Data" },
					{ 0, 0 }
				};
				return idData;
			}
			virtual bcm::Interface *getInterface(const char *id)
			{
				if (std::string("taskctl") == id)
					return getTaskControl();
				else if (std::string("gdata") == id)
					return getGlobalData();
				else if (std::string("millgdata") == id)
					return getMillGlobalData();
				return 0;
			}
			virtual bool setInterface(bcm::Interface *iface)
			{
				if (iface == 0)
					return false;
				if (std::string("millpdata") == iface->getID()) {
					MillPersistentData *pd = dynamic_cast<MillPersistentData *>(iface);
					if (pd == 0)
						return false;
					setMillPersistentData(pd);
				} else
					return false;
				return true;
			}
		public:
			static MillMemory &instance(bcm::GetComponentResult *result)
			{
				static MillMemory object;
				if (result != 0)
					*result = object.result_;
				return object;
			}
		};

	} // namespace base

} // namespace cnc

#endif

